#include <iostream>
#include <fstream>
#include <vector>
#include <string>

using std::ifstream;

using std::cout;
using std::cin;
using std::cerr;
using std::endl;

using std::vector;
using std::string;

#define ERROR -1
#define SUCCESS 1

vector <char> mem;
int curr = 0;

int go (string source) {
	for (int i = 0; i < source.length(); ++i)
		if (source[i] == '+')
			++mem[curr];
		else if (source[i] == '-')
			--mem[curr];
		else if (source[i] == '>') {
			if (curr == mem.size() - 1)
				mem.push_back (0);
			++curr;
		}
		else if (source[i] == '<') {
			if (curr == 0)
				return ERROR;
			--curr;
		}
		else if (source[i] == '.') {
			cout << mem[curr];
		}
		else if (source[i] == ',') {
			char c;
			cin.get (c);
			mem[curr] = c;
		}
		else if (source[i] == '[') {
			int ballance = 1;
			string new_source = "";
			for (++i; i < source.length() && ballance != 0; ++i) {
				if (source[i] == '[')
					++ballance;
				else if (source[i] == ']')
					--ballance;
				if (ballance < 0)
					return ERROR;
				if (ballance != 0 || source[i] != ']')
					new_source += source[i];
			}
			--i;
			if (ballance != 0)
				return ERROR;
			while (mem[curr] != 0) {
				int result = go (new_source);
				if (result == ERROR)
					return ERROR;
			}
		}
	return SUCCESS;
}

int main(int argc, char* argv[]) {
	if (argc == 1) {
		cout << "\033[33;1mWTF?!\nUsage: " << argv[0] << " <FILE1> <FILE2> ...\033[0m\n";
		return 0;
	}
	for (int i = 1; i < argc; ++i) {
		mem.clear();
		mem.push_back (0);
		curr = 0;

		ifstream in (argv[i]);
		if (!in.good()) {
			cout << "\033[33;1mWTF?!\nFile \"" << argv[i] << "\" cannot be readen.\n";
			continue;
		}
		char c;
		string source = "";
		while (in.get(c)) {
			source += c;
		}
		int result = go (source);
		if (result == ERROR)
		  cout << "\033[33;1mWTF?!\nAnything is going wrong\nFile \"" << argv[i] << "\" is incorrect.\n";
	}
	return 0;
}

